package com.jia.interviewPro;

/**
 * 面试题 05.01. 插入
 */
public class Pro0501 {
    public int insertBits(int N, int M, int i, int j) {
        N &= ~(((1<<(j - i + 1)) - 1) << i); //清除N的j到i位
        N |= (M <<i);  //所有的M左移i位，题目保证j到i位之间能放下M
        return N;
    }

    public static void main(String[] args) {
        Pro0501 pro0501 = new Pro0501();
        System.out.println(Integer.toBinaryString(pro0501.insertBits(0b10000000000, 0b10011, 2, 6)));;
    }
}
